package controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import model.Simulator;

public class SimulatorController extends AbstractController implements ActionListener 
{
	// Object ID
	public static final long serialVersionUID = 5555555;
	// Elements
    private JButton btnStep_1;
    private JButton btnStep_100;
    private JButton start;
    private JButton stop;
    private JButton reset;
    
    /**
     * Create a view of the given width and height.
     * @param height The simulation's height.
     * @param width  The simulation's width.
     * @param Simulator simulator - The Simulator object.
     */
	public SimulatorController(Simulator simulator)
    {
		// AbstractController
    	super(simulator);
    	
        // Create the SimulatorView window
        createView();
    }
    
	/**
	 * Create the SimulatorView JFrame
	 */
	protected void createView() 
	{
		// Panel settings
		setBorder(new EmptyBorder(5, 5, 5, 5));
		setLayout(null);
		
		// Button step 1
		btnStep_1 = new JButton("Step 1");
		btnStep_1.addActionListener(this);
		btnStep_1.setBounds(10, 10, 89, 25);
		add(btnStep_1);
		
		// Button step 100
	    btnStep_100 = new JButton("Step 100");
	    btnStep_100.addActionListener(this);
	    btnStep_100.setBounds(10, 40, 89, 25);
		add(btnStep_100);
		
		// Button start
		start = new JButton("Start");
		start.addActionListener(this);
		start.setBounds(10, 70, 89, 25);
		add(start);
		
		// Button stop
		stop = new JButton("Stop");
		stop.addActionListener(this);
		stop.setBounds(10, 100, 89, 25);
		add(stop);
		
		// Button reset
		reset = new JButton("Reset");
		reset.addActionListener(this);
		reset.setBounds(10, 130, 89, 25);
		add(reset);

	}

	@Override
	public void updateView() 
	{

	}
	
    /**
    * Action handler
    * @param ActionEvent action
    */
   public void actionPerformed(ActionEvent action)
   {
	   	// Button Step 1
	   	if(action.getSource().equals(btnStep_1))
   		simulator.simulate(1);
	
	   	// Button Step 100
	   	if(action.getSource().equals(btnStep_100))
		simulator.simulate(100);
	   	
	   	// Start simulation
	 	if(action.getSource().equals(start))
 		simulator.start();
	 	
	 	// Stop simulation
	 	if(action.getSource().equals(stop))
	    simulator.stop();
	 	
	 	// Reset simulation
	 	if(action.getSource().equals(reset))
	 	simulator.reset();	
   }
}